package main

import (
	"fmt"
)

func createWorker(id int) <-chan int {
	c := make(chan int)

	go func() {
		defer close(c)

		for i := 0; i < 5; i++ {
			c <- i
		}
	}()

	return c
}

func main() {
	workerChannel := createWorker(2)

	for data := range workerChannel {
		fmt.Printf("Received: %d\n", data)
	}

	fmt.Println("All data received.")
}
